package com.xcity.game.task;

import com.xcity.game.task.condition.BuildAttackTaskCondition;
import com.xcity.game.task.condition.BuildIncomeTaskCondition;
import com.xcity.game.task.condition.CreateBuildTaskCondition;
import com.xcity.game.task.condition.DailySignTaskCondition;
import com.xcity.game.task.condition.EmployeeEnterBuildTaskCondition;
import com.xcity.game.task.condition.EquipEnhanceTaskCondition;
import com.xcity.game.task.condition.FeedPetTaskCondition;
import com.xcity.game.task.condition.GameShareTaskCondition;
import com.xcity.game.task.condition.GetItemTaskCondition;
import com.xcity.game.task.condition.GetPetTaskCondition;
import com.xcity.game.task.condition.JoinArenaTaskCondition;
import com.xcity.game.task.condition.PVEHeroTaskCondition;
import com.xcity.game.task.condition.PVENomalTaskCondition;
import com.xcity.game.task.condition.PVETaskCondition;
import com.xcity.game.task.condition.PeakRoadTaskCondition;
import com.xcity.game.task.condition.PlayerLevelUpTaskCondition;
import com.xcity.game.task.condition.RESStageTaskCondition;
import com.xcity.game.task.condition.RecruitEmployeeTaskCondition;
import com.xcity.game.task.condition.RecuiteEmployeeStoneTaskCondition;
import com.xcity.game.task.condition.TapLikeTaskCondition;
import com.xcity.game.task.condition.TrainEmployeeLevelTaskCondition;
import com.xcity.game.task.condition.TrainEmployeeTimesTaskCondition;
import com.xcity.game.task.condition.TurntableTaskCondition;
import com.xcity.game.task.condition.UpgradeBuildLevelTaskCondition;
import com.xcity.game.task.condition.UpgradeBuildTimesTaskCondition;
import com.xcity.game.task.condition.WashPetTaskCondition;

import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;

public abstract class TaskCondition {

	/**
	 * @see TaskDetector
	 */
	protected byte type;
	
	public TaskCondition(TaskTemplate template) {
		this.type = template.getConditionId();
	}
	
	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	private static TIntObjectMap<TaskCondition> conds = new TIntObjectHashMap<TaskCondition>();
	public static TaskCondition create(TaskTemplate template) {
		TaskCondition cond = conds.get(template.getId());
		if (cond != null) {
			return cond;
		}
		switch (template.getConditionId()) {
			case TaskDetector.PVE_FIGHT:
				cond = new PVETaskCondition(template);
				break;
			case TaskDetector.ATTACK_BUILD:
			case TaskDetector.BE_ATTACKED:
				cond = new BuildAttackTaskCondition(template);
				break;
			case TaskDetector.UPGRADE_BUILD_TIMES:
				cond = new UpgradeBuildTimesTaskCondition(template);
				break;
			case TaskDetector.UPGRADE_BUILD_LEVEL:
				cond = new UpgradeBuildLevelTaskCondition(template);
				break;
			case TaskDetector.CREATE_BUILDING:
				cond = new CreateBuildTaskCondition(template);
				break;
			case TaskDetector.BUILD_INCOME:
				cond = new BuildIncomeTaskCondition(template);
				break;
			case TaskDetector.TURNTABLE_PLAY:
				cond = new TurntableTaskCondition(template);
				break;
			case TaskDetector.GET_PET:
				cond = new GetPetTaskCondition(template);
				break;
			case TaskDetector.FEED_PET:
				cond = new FeedPetTaskCondition(template);
				break;
			case TaskDetector.PLAY_PET:
				cond = new FeedPetTaskCondition(template);
				break;
			case TaskDetector.WASH_PET:
				cond = new WashPetTaskCondition(template);
				break;
			case TaskDetector.RECRUIT_EMPLOYEE:
				cond = new RecruitEmployeeTaskCondition(template);
				break;
			case TaskDetector.TRAIN_EMPLOYEE_TIMES:
				cond = new TrainEmployeeTimesTaskCondition(template);
				break;
			case TaskDetector.TRAIN_EMPLOYEE_LEVEL:
				cond = new TrainEmployeeLevelTaskCondition(template);
				break;
			case TaskDetector.LEVEL_UP:
				cond = new PlayerLevelUpTaskCondition(template);
				break;
			case TaskDetector.GET_ITEM:
				cond = new GetItemTaskCondition(template);
				break;
			case TaskDetector.TAKE_EMPLOYEE_IN_THE_BUILDING:
				cond = new EmployeeEnterBuildTaskCondition(template);
				break;
			case TaskDetector.JOIN_ARENA:
				cond = new JoinArenaTaskCondition(template);
				break;
			case TaskDetector.DAILY_SIGN:
				cond = new DailySignTaskCondition(template);
				break;
			case TaskDetector.TAP_LIKE:
				cond = new TapLikeTaskCondition(template);
				break;
			case TaskDetector.EQUIP_ENHANCE:
				cond = new EquipEnhanceTaskCondition(template);
				break;
			case TaskDetector.RECRUIT_EMPLOYEE_STONE:
				cond = new RecuiteEmployeeStoneTaskCondition(template);
				break;
			case TaskDetector.PVE_NORMAL_COUNT:
				cond = new PVENomalTaskCondition(template);
				break;
			case TaskDetector.PVE_HERO_COUNT:
				cond = new PVEHeroTaskCondition(template);
				break;
			case TaskDetector.RES_COUNT:
				cond = new RESStageTaskCondition(template);
				break;
			case TaskDetector.PEAK_ROAD_FINISH:
				cond = new PeakRoadTaskCondition(template);
				break;
			case TaskDetector.GAME_SHARE:
				cond = new GameShareTaskCondition(template);
				break;
		}
		if (cond != null) {
			conds.put(template.getId(), cond);
		}
		return cond;
	}
	abstract public int toClientCond();
}
